package com.medical.controller;

import com.github.pagehelper.PageInfo;
import com.medical.entity.SysMbfl;
import com.medical.service.MbflService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/mbfl")
public class MbflController extends BaseControllelr<SysMbfl> {
    @Autowired
    private MbflService mbflService;

    /**
     * 获取用户信息列表
     *
     * @param model
     * @return
     */
    @RequestMapping("/getMbflList")
    public String getMbflList(Integer currentPage, Integer limit, HttpServletRequest request, Model model) {
        String mbflName = request.getParameter("context");
        currentPage = currentPage != null ? currentPage : 1;
        limit = limit != null ? limit : 10;

        PageInfo<SysMbfl> pageInfo = mbflService.getMbflList(mbflName, currentPage, limit);

        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("context", mbflName);

        return "/mbfl/mbfl_list";

    }

    /**
     * 打开添加页面
     *
     * @param model
     * @return
     */
    @RequestMapping("/openAdd")
    public String openAdd(Model model) {
        return "/mbfl/mbfl_add";
    }

    /**
     * 添加用户信息
     *
     * @param sysMbfl
     * @param model
     * @return
     */
    @RequestMapping("/add")
    public String add(SysMbfl sysMbfl, HttpServletRequest request, Model model) {
        mbflService.addMbfl(sysMbfl);
        return getMbflList(1, 10, request, model);
    }

    /**
     * 打开编辑页面
     *
     * @param model
     * @return
     */
    @RequestMapping("/openEdit")
    public String openEdit(Integer id, Model model) {
        SysMbfl sysMbfl = mbflService.getMbflById(id);
        model.addAttribute("13Mbfl", sysMbfl);
        return "/mbfl/mbfl_edit";
    }

    /**
     * 更新
     *
     * @param sysMbfl
     * @param model
     * @return
     */
    @RequestMapping("/edit")
    public String edit(SysMbfl sysMbfl, HttpServletRequest request, Model model) {
        mbflService.edit(sysMbfl);
        return getMbflList(1, 10, request, model);
    }

    /**
     * 删除
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/delete")
    public String delete(Integer id, HttpServletRequest request, Model model) {
        mbflService.delete(id);
        return getMbflList(1, 10, request, model);
    }
}



